import { HttpParams } from '@angular/common/http';
import { NzTreeNodeOptions } from 'ng-zorro-antd/tree';
import { Observable } from 'rxjs';
import { RequestService } from './request.service';
import { PhasedTaskParam, PhasedTaskWithChildrenParam } from './../model/task';
import { Injectable } from '@angular/core';
import { CommonApi } from './commonApi';


@Injectable()
export class PhasedTaskApiService extends CommonApi<PhasedTaskParam>{

  constructor(
    private request: RequestService
  ) {
    super(request, '/phased');
  }

  listWithChildren(param?: HttpParams): Observable<Array<PhasedTaskWithChildrenParam>> {
    const url = this.baseUrl + '/listWithChildren';
    return this.request.get(url, param);
  }

  updateTaskProcessStatus(id: number, status: number): Observable<PhasedTaskParam> {
    const url = this.baseUrl + '/updateProcessStatus';
    const data = new FormData();
    data.append('id', id.toPrecision());
    data.append('status', status.toPrecision());
    return this.request.post(url, data);
  }

  listTreeView(id: number): Observable<NzTreeNodeOptions> {
    const url = this.baseUrl + '/treeStructure/' + id;
    return this.request.get(url);
  }
}
